package cn.fintecher.gis.web;


import cn.fintecher.gis.entity.BusinessLayer;
import cn.fintecher.gis.entity.QBusinessLayer;
import cn.fintecher.gis.respository.BusinessLayerRepository;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/businessLayerController")
@Api(value = "业务图层信息管理", description = "业务图层信息管理")
public class BusinessLayerController {

    private final Logger logger = LoggerFactory.getLogger(BusinessLayerController.class);

    @Autowired
    private BusinessLayerRepository businessLayerRepository;

    @GetMapping("/queryBusinessLayerByGroupId")
    @ApiOperation(value = "查询图层信息", notes = "查询图层信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<BusinessLayer>> queryBusinessLayerByGroupId(Pageable pageable,
                                                                           @RequestParam("groupId") String groupId) {
        BooleanBuilder builder = new BooleanBuilder();
        QBusinessLayer qBusinessLayer = QBusinessLayer.businessLayer;
        if (groupId != null && !groupId.trim().equals("")) {
            builder.and(qBusinessLayer.groupId.eq(groupId));
        }
        Page<BusinessLayer> page = businessLayerRepository.findAll(builder, pageable);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("/getBusinessLayerList")
    @ApiOperation(value = "查询所有的业务图层", notes = "查询所有的业务图层")
    public ResponseEntity<List<BusinessLayer>> getBusinessLayerList() {
        List<BusinessLayer> list = businessLayerRepository.findAll();
        return ResponseEntity.ok().body(list);
    }
}
